#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

/*
 * +1 action
 * choice1 - +2 coins
 * choice2 - discard hand, draw 4.  Other players discard hand and redraw if hand size > 4.
 */
void minion_test(void)
{
	int i, j, k;
	int choice1, choice2;
	int prev_coins;
	int prev_actions;
	int prev_minion_count;
	int num_players = 4;
	struct gameState state;

	init_test_data(&state, num_players);

	srand(time(NULL));

	for (i = 0; i < MAX_ITERATIONS; i++) {
		for (j = 0; j < num_players; j++) {
			state.deckCount[j] = 50;
			for (k = 0; k < state.deckCount[j]; k++) {
				state.deck[j][k] = random_card();
			}

			state.handCount[j] = 5;
		}

		for (j = 0; j < 4; j++) {
			state.hand[0][j] = random_card();
		}
		state.hand[0][4] = minion;

		prev_coins = state.coins;
		prev_minion_count = card_count(state.hand[0], minion, state.handCount[0]);

		choice1 = rand() % 2;
		choice2 = !choice1;

		prev_actions = state.numActions;
		prev_coins = state.coins;
		prev_buys = state.numBuys;

		minion_effect(&state, 0, 4, choice1, choice2);

		assert(card_count(state.hand[0], minion, state.handCount[0]) == prev_minion_count - 1);
		assert(state.numActions == prev_actions + 1);


		if (choice1) {
			assert(state.numBuys == prev_buys + 2);
		} else {
			assert(state.handCount[0] == 4);

			// Guaranteed to test this since hand count is 5 for each player
			for (j = 1; j < num_players; j++) {
				assert(state.handCount[j] == 4)
			}
		}
	}
}

int main(int argc, char const *argv[])
{
	minion_test();
	return 0;
}